package com.wbihua.grpc.demo.spring.mapper;

import cn.hutool.core.text.CharSequenceUtil;
import com.wbihua.grpc.demo.entity.User;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

@Slf4j
public class MapperProxy implements InvocationHandler {

    public Object getInstance(Class mapperInterface){
        return Proxy.newProxyInstance(mapperInterface.getClassLoader(),new Class[]{mapperInterface},this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        log.info(CharSequenceUtil.format("{} : {}", method.getName(), Arrays.asList(args)));
        return new User(1L,String.valueOf(args[0]));
    }
}
